using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_VKPWEFT
    {
        public void MapICC_VKPWEFT(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_VKPWEFT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryICC_VKPWEFT(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapICC_VKPWEFT(ref dwLocal, dwData);

            if (!flgExist)
            {
                dwLocal["ROWNID"] =INTEXDBC.GetSeq();
                InsertICC_VKPWEFT(dwLocal, 1);
            }
            UpdateICC_VKPWEFT(dwLocal);
        }
        public void InsertICC_VKPWEFT(DataRow dwData, int option = 1)
        {
            string table = "VVPACK";  //VVPMANDANT	VVPLIEFSCH	VVPPACKNR
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "INSERT INTO ICC_VKPWEFT(CONTROL,MANDANT,ROWNID,VKPAUFKRS,VKPAUFLFD,MPOS,MYARN,MUNIT,MUSAGE,MPRICEM,MVALUEM,MPRICED,MVALUED,MCOST,NEWUSER,NEWTIME,CHGUSER,CHGTIME)"
                        + "VALUES(:CONTROL,:MANDANT,:ROWNID,:VKPAUFKRS,:VKPAUFLFD,:MPOS,:MYARN,:MUNIT,:MUSAGE,:MPRICEM,:MVALUEM,:MPRICED,:MVALUED,:MCOST,:NEWUSER,:NEWTIME,:CHGUSER,:CHGTIME)";
                    or1.Parameters.Add("CONTROL", OracleType.NVarChar).Value = dwData["CONTROL"].ToString();
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("VKPAUFKRS", OracleType.NVarChar).Value = dwData["VKPAUFKRS"].ToString();
                    or1.Parameters.Add("VKPAUFLFD", OracleType.NVarChar).Value = dwData["VKPAUFLFD"].ToString();
                    or1.Parameters.Add("MPOS", OracleType.NVarChar).Value = dwData["MPOS"].ToString();
                    or1.Parameters.Add("MYARN", OracleType.NVarChar).Value = dwData["MYARN"].ToString();
                    or1.Parameters.Add("MUNIT", OracleType.NVarChar).Value = dwData["MUNIT"].ToString();
                    or1.Parameters.Add("MUSAGE", OracleType.NVarChar).Value = dwData["MUSAGE"].ToString();
                    or1.Parameters.Add("MPRICEM", OracleType.NVarChar).Value = dwData["MPRICEM"].ToString();
                    or1.Parameters.Add("MVALUEM", OracleType.NVarChar).Value = dwData["MVALUEM"].ToString();
                    or1.Parameters.Add("MPRICED", OracleType.NVarChar).Value = dwData["MPRICED"].ToString();
                    or1.Parameters.Add("MVALUED", OracleType.NVarChar).Value = dwData["MVALUED"].ToString();
                    or1.Parameters.Add("MCOST", OracleType.NVarChar).Value = dwData["MCOST"].ToString();
                    or1.Parameters.Add("NEWUSER", OracleType.NVarChar).Value = dwData["NEWUSER"].ToString();
                    or1.Parameters.Add("NEWTIME", OracleType.NVarChar).Value = dwData["NEWTIME"].ToString();
                    or1.Parameters.Add("CHGUSER", OracleType.NVarChar).Value = dwData["CHGUSER"].ToString();
                    or1.Parameters.Add("CHGTIME", OracleType.NVarChar).Value = dwData["CHGTIME"].ToString();
                    break;
                default:
                    break;
            }

            Connect2Proxy(or1);
        }
        public DataSet QueryICC_VKPWEFT(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = " SELECT * FROM ICC_VKPWEFT WHERE MANDANT=:MANDANT AND  ROWNID=:ROWNID";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    break;
                case 2:
                    or1.CommandText = " SELECT * FROM ICC_VKPWEFT WHERE MANDANT=:MANDANT  AND VKPAUFKRS=:VKPAUFKRS AND VKPAUFLFD=:VKPAUFLFD"
                         + " ORDER BY VKPAUFKRS,VKPAUFLFD,MPOS";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("VKPAUFKRS", OracleType.NVarChar).Value = dwData["VKPAUFKRS"].ToString();
                    or1.Parameters.Add("VKPAUFLFD", OracleType.NVarChar).Value = dwData["VKPAUFLFD"].ToString();
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_VKPWEFT";
            Return = Result;
            return Return;
        }
        public void UpdateICC_VKPWEFT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            #region====Command====
            or1.CommandText = " UPDATE ICC_VKPWEFT SET "
            + "CONTROL=:CONTROL,"
            + "MANDANT=:MANDANT,"
            + "VKPAUFKRS=:VKPAUFKRS,"
            + "VKPAUFLFD=:VKPAUFLFD,"
            + "MPOS=:MPOS,"
            + "MYARN=:MYARN,"
            + "MUNIT=:MUNIT,"
            + "MUSAGE=:MUSAGE,"
            + "MPRICEM=:MPRICEM,"
            + "MVALUEM=:MVALUEM,"
            + "MPRICED=:MPRICED,"
            + "MVALUED=:MVALUED,"
            + "MCOST=:MCOST,"
            + "NEWUSER=:NEWUSER,"
            + "NEWTIME=:NEWTIME,"
            + "CHGUSER=:CHGUSER,"
            + "CHGTIME=:CHGTIME "
                + " WHERE  "
                + "    ROWNID=:ROWNID ";
            #endregion
            #region====Parameters====
            or1.Parameters.Add("CONTROL", OracleType.NVarChar).Value = dwData["CONTROL"].ToString();
            or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
            or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
            or1.Parameters.Add("VKPAUFKRS", OracleType.NVarChar).Value = dwData["VKPAUFKRS"].ToString();
            or1.Parameters.Add("VKPAUFLFD", OracleType.NVarChar).Value = dwData["VKPAUFLFD"].ToString();
            or1.Parameters.Add("MPOS", OracleType.NVarChar).Value = dwData["MPOS"].ToString();
            or1.Parameters.Add("MYARN", OracleType.NVarChar).Value = dwData["MYARN"].ToString();
            or1.Parameters.Add("MUNIT", OracleType.NVarChar).Value = dwData["MUNIT"].ToString();
            or1.Parameters.Add("MUSAGE", OracleType.NVarChar).Value = dwData["MUSAGE"].ToString();
            or1.Parameters.Add("MPRICEM", OracleType.NVarChar).Value = dwData["MPRICEM"].ToString();
            or1.Parameters.Add("MVALUEM", OracleType.NVarChar).Value = dwData["MVALUEM"].ToString();
            or1.Parameters.Add("MPRICED", OracleType.NVarChar).Value = dwData["MPRICED"].ToString();
            or1.Parameters.Add("MVALUED", OracleType.NVarChar).Value = dwData["MVALUED"].ToString();
            or1.Parameters.Add("MCOST", OracleType.NVarChar).Value = dwData["MCOST"].ToString();
            or1.Parameters.Add("NEWUSER", OracleType.NVarChar).Value = dwData["NEWUSER"].ToString();
            or1.Parameters.Add("NEWTIME", OracleType.NVarChar).Value = dwData["NEWTIME"].ToString();
            or1.Parameters.Add("CHGUSER", OracleType.NVarChar).Value = dwData["CHGUSER"].ToString();
            or1.Parameters.Add("CHGTIME", OracleType.NVarChar).Value = dwData["CHGTIME"].ToString();
            #endregion
            Connect2Proxy(or1);
        }
        public DataSet DeleteICC_VKPWEFT(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = " DELETE FROM ICC_VKPWEFT WHERE  ROWNID=:ROWNID"; ;
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    break;
                case 2:
                    or1.CommandText = "DELETE FROM ICC_VKPWEFT WHERE MANDANT=:MANDANT AND VKPAUFKRS=:VKPAUFKRS AND VKPAUFLFD=:VKPAUFLFD";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("VKPAUFKRS", OracleType.NVarChar).Value = dwData["VKPAUFKRS"].ToString();
                    or1.Parameters.Add("VKPAUFLFD", OracleType.NVarChar).Value = dwData["VKPAUFLFD"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
            return Result;
        }
    }
}
